﻿#ifndef COMMON_H
#define COMMON_H
#include <QString>
#include <QVector>
#include <QObject>
#include <QMap>
#include <QTcpSocket>
#include <QMetaEnum>
#include <QStringLiteral>
#include "deviceattributes.h"
#include "datatypes.h"
/************* 日志配置 ********************/
#define LOG_TERMINAL QStringLiteral("Terminal")
#define LOG_FILE QStringLiteral("File")
#define LOG_ALL QStringLiteral("All")
#define LEVEL_TRACE 6
#define LEVEL_DEBUG 5
#define LEVEL_INFO 4
#define LEVEL_WARNING 3
#define LEVEL_ERROR 2
#define LEVEL_FATAL 1
#define LEVEL_OFF 0

#define ERROR_VALUE -1e36

#define _ISALW //扫描同时获取轨迹数据

enum class LogLevel {
    Info,
    Warning,
    Error,
    Debug
};

#include <QComboBox>
#include <QMutex>
#include <QObject>
class Utils : public QObject
{
    Q_OBJECT
public:
    static Utils *instance();
    static QString getAppLanguage();
    static void setAppLanguage(const QString &language);

    static void saveGeometry(const QRect rect);
    static QRect loadGeometry();
    static void saveWindowState(const bool isFullScreen);
    static bool loadWindowState();
    static int getWidgetWidth();
    static int getWidgetHeight();

    static QString resolveDriverPathIO(DeviceInterfaceType type);
    static QString resolveDriverPath(DeviceType type, const QString &libPath);
    static int findComboBoxIndexByData(QComboBox *cb, int id);
    static bool findCalibrationDataByFrequency(const Exec::CalTablePtr &calTable, double freq_Hz, Exec::CalPoint &out);

    static bool saveLevelScanConfig(const LevelScanningConfig &config);
    static LevelScanningConfig loadLevelScanConfig();
    static QString loadTemperatureHumiditySensorConfig(); //温湿度传感器

private:
    explicit Utils();
    static Utils *m_instance;
    static QMutex *mutex;

    class Destruct
    {
        ~Destruct()
        {
            if (Utils::m_instance) {
                delete m_instance;
                m_instance = nullptr;
            }
        }
    };
    static Destruct destruct;
};

#endif // COMMON_H
